<?php
namespace Infinity;


class Util {
  public static function staticFunc($name, $callback) {
    $static = &drupal_static($name, array());
    if(!isset($static[$name])) {
      $static[$name] = $callback();
    }
    return $static[$name];
  }

  public static function switchLanguage($language_code = 'en', $type = 'language') {
    $path = drupal_is_front_page() ? '<front>' : $_GET['q'];
    $languages = language_negotiation_get_switch_links($type, $path);
    $language = $languages->links[$language_code];
    drupal_goto($path, array(
      'language' => $language['language']
    ));
  }
  
  public static function touch($name) {
    $filename = 'public://touch/'.$name.'.txt';
    $filename = drupal_realpath($filename);
    $count = 1;
    if(file_exists($filename)) {
      $count = file_get_contents($filename);
      $count = (int)$count + 1;
    }
    file_put_contents($filename, $count);
    dpm($filename);
  }
}